package com.bjsdzk.collector.controller;

import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;

import javax.annotation.PostConstruct;

import com.bjsdzk.backend.rpc.XiYuService;
import com.bjsdzk.backend.rpc.after.OneNetServiceCollect;
import com.bjsdzk.backend.rpc.before.TelecomSericePlatform;
import com.bjsdzk.backend.rpc.collector.BaseLocalDeviceCollect;
import com.bjsdzk.backend.rpc.entity.OneNetCallBackResult;
import com.bjsdzk.backend.rpc.entity.collector.DeviceCmdInfo;
import com.bjsdzk.backend.rpc.entity.collector.DeviceInfo;
import com.bjsdzk.backend.rpc.serial.SerialPortService;
import com.bjsdzk.backend.rpc.serial.SeroalportPlatformService;
import com.bjsdzk.collector.entity.onenet.OneNetResult;
import com.bjsdzk.collector.entity.response.Result;
import com.bjsdzk.collector.entity.response.ResultHandler;
import com.bjsdzk.collector.one2one.OnlyServer;
import com.bjsdzk.collector.rpc.OneNetCollectService;
import com.bjsdzk.collector.serviceImp.ParamsSettingService;
import com.bjsdzk.collector.utils.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.datagram.DatagramSocket;
import io.vertx.core.datagram.DatagramSocketOptions;
import io.vertx.ext.mongo.MongoClient;
import io.vertx.ext.mongo.UpdateOptions;
import io.vertx.rabbitmq.RabbitMQClient;
import io.vertx.rabbitmq.RabbitMQConsumer;
import io.vertx.redis.RedisClient;
import io.vertx.redis.RedisOptions;
import org.apache.commons.lang3.StringUtils;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.redis.core.Cursor;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.fastjson.JSONObject;
import com.bjsdzk.backend.rpc.APPService;
import com.bjsdzk.backend.rpc.CollectorService;
import com.bjsdzk.backend.rpc.before.AliIotBefore;
import com.bjsdzk.collector.config.AllLoadBalance;
import com.bjsdzk.collector.constant.Constant;
import com.bjsdzk.collector.entity.HttpClientResult;
import com.bjsdzk.collector.entity.model.Command;
import com.bjsdzk.collector.entity.yuanda.RealTimeData;
import com.bjsdzk.collector.mapper.CommandMapper;
import com.bjsdzk.collector.serviceImp.TelecomSecondService;
import com.bjsdzk.collector.serviceImp.TelecomService;
import com.fasterxml.jackson.databind.ObjectMapper;

import io.vertx.core.Vertx;
import io.vertx.core.eventbus.EventBus;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;
import lombok.Setter;

import static java.lang.Thread.sleep;

@RestController
@RequestMapping("/test")
//@Profile({"dev","test"})
//@Adaptive
@Api(tags="1.测试",description=" ")
public class TestController {

	private static Logger logger = LoggerFactory.getLogger(TestController.class);

	private static CommandMapper commandMapper;

	private static Map<String, Object> readMap = new ConcurrentHashMap<>();

	private CommandMapper commandMapper2;

	@Setter
	public AllLoadBalance allLoadBalance;

	@Autowired
	private MongoClient mongoClient;

	@PostConstruct
	public void beforeInit() {
		commandMapper = commandMapper2;
	}

	@Autowired
	private Vertx vertx;
	//	@Resource(name="secondMongoTemplate")
//    private MongoTemplate secondMongoTemplate;
	@Autowired
	private MongoTemplate mongoTemplate;
	@Autowired
	private ObjectMapper objectMapper;
	@Autowired
	private TelecomService telecomService;
	@Autowired
	private ParamsSettingService paramsSettingService;

	@Autowired
	private TelecomSecondService telecomSecondService;

	@Autowired
	private RedisClient redis;

	@Autowired
	private OneNetCollectService oneNetCollectService;

	@Reference(check = false, version = "1.0.0", lazy = true,retries = 1,timeout = 30000)
	private OneNetServiceCollect oneNetC;

	@Reference(check = false, version = "1.0.0", lazy = true, cluster = "failsafe")
	private CollectorService collectorService;

	@Reference(check = false, version = "1.0.0", lazy = true)
	private XiYuService xiYuService;

	@Reference(check = false, version = "1.0.0", lazy = true)
	private TelecomSericePlatform telecomSericePlatform;



	//@Reference(check = false, version = "1.0.0", lazy = true, loadbalance = "allLoadBalance",filter="dubboFilter")
//	@Reference(check = false, version = "1.0.0", lazy = true, mock = "com.bjsdzk.collector.rpc.MockPlatformService")
//	private Platform2Service platform2Service;

	@Reference(check = false, version = "1.0.0", lazy = true, loadbalance = "allLoadBalance")
	private AliIotBefore aliIotBefore;

	@Reference(check = false, version = "1.0.0", lazy = true, loadbalance = "allLoadBalance")
	private SerialPortService serialPortService;

	@Reference(check = false, version = "1.0.0", lazy = true)
	private APPService aPPService;


//	@Reference(check = false, version = "1.0.0", lazy = true,group = "platform"/*,filter="dubboFilter"*/)
	@Reference(check = false, version = "1.0.0",group = "platform", lazy = true ,retries = -1)
	private SeroalportPlatformService seroalportPlatformService;
	@Autowired
	private RabbitMQClient client;
	@Autowired
	private RedisTemplate<String,String> redisTemplate;
	@Reference(check = false, version = "1.0.0", lazy = true,validation = "true")
	private BaseLocalDeviceCollect localDeviceCollect;


	String QUEUE_NAME = "test_quue1";
	@GetMapping("/rabbitSendMessage")
	public void   rabbitSendMessage(String  content) {

		if (content == null) {
			content = "Hello RabbitMQ, from Vert.x !";
		}
		String finalContent = content;
		System.out.println(System.currentTimeMillis());
		String EXCHANGE_NAME = "test_exchange";
		String EXCHANGE_TYPE = "fanout";
		client.start(dd -> {
			if (dd.succeeded()) {
				boolean connected = client.isOpenChannel();

//				client.exchangeDeclare(EXCHANGE_NAME, EXCHANGE_TYPE, true, false, h -> {
//					if (h.succeeded()) {
//						client.queueDeclare(QUEUE_NAME, true, false, false, q -> {
//							if (q.succeeded()) {
//								client.queueBind(QUEUE_NAME, EXCHANGE_NAME, "", b -> {
//									if (b.failed()) {
//										logger.error(b.cause().getMessage());
//									}
//								});
//							} else {
//								logger.error(q.cause().getMessage());
//							}
//						});
//					} else {
//						logger.error(h.cause().getMessage());
//					}
//
//				});

				JsonObject message = new JsonObject().put("body", finalContent);
				logger.info("---" + System.currentTimeMillis());
				for (int i = 0; i < 500; i++) {

					client.basicPublish(EXCHANGE_NAME, "", message, h -> {
						if (h.succeeded()) {
							logger.info("--" + System.currentTimeMillis());
						}
					});
				}
			} else {
				logger.error(dd.cause().getMessage());
			}
		});
	}



	@GetMapping("/rabbitConsumerMessage")
	public void   rabbitConsumerMessage(String  content) {
		client.start(startResult -> {
			if (startResult.succeeded()) {
				client.basicConsumer(QUEUE_NAME, h -> {
					if (h.succeeded()) {
						RabbitMQConsumer consumerResult = h.result();
						consumerResult.handler(message -> {
							logger.info(message.body().toString());
						});
					} else {
						h.cause().printStackTrace();
					}
				});
			}
		});

	}

	@GetMapping("/testchuan")
	public Result testchuan(/*@Validated*/ DeviceCmdInfo deviceCmdInfo) {
		com.bjsdzk.backend.rpc.entity.response.Result result = localDeviceCollect.cmd(deviceCmdInfo);
		logger(result.toString());
		return ResultHandler.ok();
	}
	@GetMapping("/logger")
	public void   logger(String  content) {
        logger.info("info");
        logger.debug("debug");
        logger.trace("TRACE");
        logger.error("error");
        logger.warn("warn");

	}
	@GetMapping("/sendUdp")
	public String  sendUdp(Integer size) throws UnknownHostException, InterruptedException {
		int port = 62008;
		InetAddress addr = InetAddress.getLocalHost();
		String address = addr.getHostAddress();
		Vertx vertx = Vertx.vertx();
		EventBus eventBus = vertx.eventBus();
		DatagramSocket socket = vertx.createDatagramSocket(new DatagramSocketOptions());
		byte[] cmd = Utils.hexStringToByteArray("F1AC050000A4001698CC4D30001310005ED7564B00EC00111C0000000000000000000000000000005ED751FE00000000009FFFFF01E40000000000000000016B0000000000000000800000000\r\n" +
				"0000000009FFFFF01E50000000000000000012300000000000000008000080000000000009FFFFF01E60000000000000000012800000000000000008000080000000000009FFFFF01E70000000000000000012900000000000000008000080000000000009FFFFF567E1149");
		Buffer buffer = Buffer.buffer().appendBytes(cmd);
		if (size == null) {
			size = 300;
		}
		AtomicInteger  count=new AtomicInteger(0);
		for (int i = 0; i < size; i++) {
			List<String> asList = Arrays.asList("47.113.189.134","1.119.185.220");
			asList.forEach(ele -> {
				socket.send(buffer, port, ele, asyncResult -> {
					logger.debug("Send succeeded? "+ele+"---" +count.incrementAndGet());
				});
			});
			sleep(100);
		}
		return "";
	}

	@GetMapping("/telecomSericePlatform")
	public Object telecomSericePlatform() {
		OneNetCallBackResult oneNetCallBackResult =  new OneNetCallBackResult();
		oneNetCallBackResult.setCommand("asdfsd");
		oneNetCallBackResult.setData("asdfsdddddd");
		oneNetCallBackResult.setImei("88888888888888888888888888888888888");
		telecomSericePlatform.cmdCallBack(oneNetCallBackResult);
		return "ok";
	}

	@GetMapping("/mongoclient")
	public String mongoclient(Integer type,Integer v) {

		JsonObject query = new JsonObject().put("deviceId", "BB000844").put("type", type);
		JsonObject entity = new JsonObject();
		entity.put("deviceId", "BB000844");
		entity.put("port", "62002");
		entity.put("deviceType", "678");
		entity.put("type", type);
		entity.put("v", v);
		entity.put("des", "信号强度");
		JsonObject update = new JsonObject().put("$set", entity);
		UpdateOptions options = new UpdateOptions().setMulti(false).setUpsert(true);
		mongoClient.updateCollectionWithOptions("books", query, update, options, res -> {
			if (res.succeeded()) {
				System.out.println("Book updated !");
			} else {
				res.cause().printStackTrace();
			}
		});

		return "";
	}


	@GetMapping("/serialPortService")
	public String serialPortService(String oper,String deviceCode,Integer deviceNum,String deviceType,String messageId)  {
//		if (sendId ==null){
////			sendId="0024";
////		}
////		if (value ==null){
////			value="0000";
////		}
////		if (deviceNum ==null){
////			deviceNum=01;
////		}
////		if (deviceType ==null){
////			deviceType="116";
////		}
////		if (messageId ==null){
////			messageId="nigedoubidddddd";
////		}
////		JsonObject json = new JsonObject();
////		json.put("port", 60006);
////		json.put("deviceType", deviceType);
////		json.put("deviceNum", deviceNum);
////		json.put("sendId", sendId);
////		json.put("value", value);
////		json.put("flag", "write");
////		json.put("source", "flatform");
////		json.put("messageId", messageId);
		if(deviceCode==null){
			deviceCode="DD000001";
		}
		JsonObject json = new JsonObject();
		json.put("deviceType", "39d7514b-4c9a-11ea-99eb-94c691264d57");
		json.put("messageId", "readShuangHuaThreshold");
		json.put("deviceCode", deviceCode);
		json.put("port", 62002);
		json.put("source", "platform");
		json.put("dtuType", "7");
		if(oper==null){
			json.put("data", "4");
			json.put("oper", "B0");
		}else if (StringUtils.equals(oper,"A1")){
			JsonArray arr = new JsonArray();
			JsonObject j = new JsonObject();
			j.put("params", "2102");
			j.put("value", 51);
			arr.add(j);
			json.put("oper", oper);
			json.put("data",arr);
		}else if (StringUtils.equals(oper,"A0")){
			json.put("oper", oper);
		}
		serialPortService.cmd(json.toString());
		return "";
	}

	@ApiOperation(value="乐鸟断路器命令测试", notes="乐鸟断路器命令测试",produces = "application/json")
	 @PostMapping("/serialPortServicel")
	public Integer error(@RequestBody List<String> list,Integer function,Integer operation,Integer port)  {
		if(port==null){
			port=62003;
		}
		if(list==null||list.isEmpty()){
			list=Arrays.asList("1");
		}
		if(function==null){
			function=205;
		}
		 JsonObject json = new JsonObject();
		 json.put("messageId", "sdlkfjasdklfjasldkjf");
		 json.put("port", port);
		 json.put("source", "platform");
		 json.put("dtuType", "12");
		 json.put("isSave", false);
		 if (operation==null){
			 json.put("operation", Constant.LNCMDTYPE_CONTRL);
		 }else if (operation==1){
			 json.put("operation", Constant.LNCMDTYPE_GETALL);
		 }
		 json.put("function", function);//205 open 206 close
		 json.put("deviceList", list);

		 serialPortService.cmd(json.toString());
		return 1;
		}


	@ApiOperation(value="乐鸟探测器命令测试", notes="乐鸟探测器命令测试",produces = "application/json")
	@GetMapping("/serialPortServicel1")
	public Integer serialPortServicel1(@RequestParam List<String> list, @RequestParam List<Integer> values,Integer port,Integer startAddress  ,String operation,Integer dataLen) {
		if (port == null) {
			port = 62004;
		}
		if (list == null || list.isEmpty()) {
			list = Arrays.asList("1");
		}
        if (values == null || values.isEmpty()) {
            values = Arrays.asList(1);
        }

		if (startAddress == null) {
			startAddress = 50;
		}
		if (operation == null) {
			operation = "02";
		}

		if (dataLen == null) {
			dataLen = 21;
		}


		JsonObject json = new JsonObject();
		json.put("messageId", "sdkjhfkasjdhfksd");
		json.put("source", "platform");
		json.put("port", port);
		json.put("dtuType", "11");
		json.put("isSave", false);
		json.put("values", values);
		json.put("operation", operation);
		json.put("deviceList", list);
		json.put("startAddress", startAddress);
		json.put("dataLen", dataLen);
		serialPortService.cmd(json.toString());
		return 1;
	}
	@ApiOperation(value="同步redis数据", notes="同步redis数据",produces = "application/json")
	@PostMapping("/redisSyn")
	public Integer redisSyn(String key) {
        try {
            RedisOptions config = new RedisOptions().setHost("1.119.185.221").setAuth("qweoiu");
            RedisClient redisClient = RedisClient.create(vertx, config);

            if (key == null) {
                key = "mod_62008";
            }
            String finalKey = key;
            redisClient.type(key, hr->{
                if (hr.succeeded()) {
                    String type = hr.result();
                    if (StringUtils.equals(type, "hash")) {
                        redisClient.hgetall(finalKey, h -> {
                            if (h.succeeded()) {
                                JsonObject result = h.result();
                                logger.info(result.toString());
								redis.hmset(finalKey, result, han -> {
                                    if (han.failed()) {
                                        PublicUtils.printException(han.cause());
                                    }else if (han.succeeded()){
                                    	logger.info("success");
									}
                                });
                            } else {
                                PublicUtils.printException(h.cause(), 333335);
                            }

                        });
                    }else {
                        redisClient.get(finalKey, h->{
                            if (h.succeeded()) {
                                String result = h.result();
                                logger.info(result );
                                redis.set(finalKey, result, han -> {
                                    if (han.failed()) {
                                        PublicUtils.printException(h.cause(), 333336);
                                    }
                                });
                            } else {
                                PublicUtils.printException(h.cause(), 333338);
                            }
                        });
                    }
                }else {
                    PublicUtils.printException(hr.cause(), 333337);
                }
            });

        } catch (Exception e) {
            PublicUtils.printException(e, 333335);
        }
        return 1;

    }

	@ApiOperation(value="更新阿里redis的设备信息", notes="更新阿里redis的设备信息",produces = "application/json")
	@GetMapping("/updateProDeviceInfo")
	public void updateProDeviceInfo() throws InterruptedException {
//		JsonObject config = new JsonObject();
//		config.put("port", 62008 + "");
//		config.put("dtuType", "13");
//		config.put("companyId", "sdssdddd");
//		config.put("heartPackage", "31");
//		config.put("hardwareType", "59");
//		for (int i=0 ;i<10000;i++){
//			JsonArray list =new JsonArray();
//			list.add("98CC4D0"+StringUtils.leftPad(i+"", 5, "0"));
//			config.put("deviceList", list.toString());
//			serialPortService.deviceAdd(config.toString());
//			Thread.sleep(10);
//		}
//
		Cursor<String> scan = RedisUtil.scan(redisTemplate, "device-*", Integer.MAX_VALUE);
		Set<String> keys = new HashSet<>(10240);
		while (scan.hasNext()) {
			keys.add(scan.next());
		}
		try {
			if (!scan.isClosed()) {
				scan.close();
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
		AtomicInteger atomicInteger=new AtomicInteger();
		keys.forEach((k) -> {
//			redis.hget(k, "currentRatio", res->{
//				if (res.succeeded()){
//					String result = res.result();
//					int i = Integer.parseInt(result);
//
//					if (i<1){
//
//					}
//
//				}
//			});
			redis.hget(k, "source", res->{
				if(res.succeeded()){
					res.result();
					if(!StringUtils.equals(res.result(), Constant.GROUP_PLATFORM)){
						logger.info(k+" xuyaogengxin key：{}",k);
						redis.hset(k, "source", "platform", h -> {

						});
					}
				}
			});


			try {
				sleep(10);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		});


//		redis.scan("",new ScanOptions(new JsonObject().put("pattern", "device-*").put("count", 2000)),res -> {
//			if (res.succeeded()) {
//				JsonArray devicesInfo = res.result();
//				devicesInfo.forEach(deviceIdKey ->{
//					redis.hgetall(deviceIdKey.toString(), h->{
//						if (h.succeeded()){
//							JsonObject deviceInfo = h.result();
//							redis.hset(BasetVerticle.getRedisKeyByDeviceId(deviceInfo.getString("deviceId")),"currentRatio",1+"",aa->{
//
//							});
//						}
//					});
//				});
//			}
//		});
	}

	@ApiOperation(value="曼顿命令测试", notes="曼顿命令测试",produces = "application/json")
	@PostMapping("/serialPortService2")
	public Integer serialPortService2(String operation,Integer port,String cmdId,String deviceHex,Double upperLimit,Double lowerLimit,String value,Integer deviceAddr,String source ,Boolean isInstantCmd)  {
		if(port==null){
			port=62008;
		}
		if(operation==null){
			operation="B5";
		}
		if(cmdId==null){
			cmdId="A2";
		}

		if(deviceHex==null){
			deviceHex="98CC4D00115F";
		}

		if(upperLimit==null){
			upperLimit=250.0;
		}

		if(lowerLimit==null){
			lowerLimit=150.0;
		}
		if(deviceAddr==null){
			deviceAddr=1;
		}

		if(value==null){
//			value="123.59.136.8";
		}

		if(source==null){
			source="platform";
		}

		JsonObject json = new JsonObject();
		json.put("messageId", "sdlkfjasdklfjasldkjf");
		json.put("port", port);
		json.put("source", source);
		json.put("dtuType", "13");
		json.put("operation", operation);
		json.put("cmdId", cmdId);
		json.put("deviceHex", deviceHex);
		json.put("upperLimit", upperLimit);
		json.put("lowerLimit", lowerLimit);
		json.put("value", value);
		json.put("deviceAddr", deviceAddr);
		json.put("isInstantCmd", isInstantCmd);

		serialPortService.cmd(json.toString());
		return 1;
	}
	 @GetMapping("/error1")
		public String error1(String a)  throws  Exception{
//         oneNetCollectService.getCmdStatus(a,"869975034708787", "SMOKE");
		return oneNetCollectService.executeCmd("KW|KAIWAN|460041935905416&869975034708787|F2|01|F7D8","869975034708787", "SMOKE");
		}

	@ApiOperation( value="",notes="卓文命令调试")
    @GetMapping("/zhuowen")
    public String zhuowencmd(String imei,String command,String oper,String num)  throws  Exception {
		JsonObject json = new JsonObject();
		if (StringUtils.isEmpty(command)) {
			command = "SET-OC";
		}
		if (imei == null) {
			imei = "860765046101462";

		}
		if (oper == null) {
			oper = "open";
		}else {
			oper = "close";
		}
		if (num == null) {
			num = "1";
		}
			if (StringUtils.equals(command, OneNetCollectService.SET_OC)) {
				List<String> list = Arrays.asList(num, oper);
				JsonArray arr = new JsonArray(list);
				json.put("content", arr.toString());
			} else if (StringUtils.equals(command, OneNetCollectService.SET_ALARM) ) {
				JsonObject con = new JsonObject();
				con.put("addr", Arrays.asList("1"));
//			     con.put("top_current",Arrays.asList("31","N"));//过流
//				//过压
//				con.put("top_voltage", Arrays.asList("170", "Y"));
//				con.put("lower_voltage",Arrays.asList("171","N"));//欠压
//				con.put("top_power",Arrays.asList("301","N"));//过功
				con.put("top_temperature",Arrays.asList("11","Y"));//过温
				json.put("content", con.toString());

			}else if (StringUtils.equals(command, OneNetCollectService.SET_WARN)) {
				JsonObject con = new JsonObject();
				con.put("addr", Arrays.asList("1"));
//				con.put("top_current",Arrays.asList("29","N"));//过流
//				//过压
//				con.put("top_voltage", Arrays.asList("169", "N"));
//				con.put("lower_voltage",Arrays.asList("168","N"));//欠压
//				con.put("top_power",Arrays.asList("299","N"));//过功
				con.put("top_temperature",Arrays.asList("10","Y"));//过温
//				con.put("(top_quantity_elec",Arrays.asList("29","N"));//限定电
//				con.put("top_leak",Arrays.asList("19","N"));//漏电流门限
				json.put("content", con.toString());

			}else if (StringUtils.equals(command, OneNetCollectService.GET_ALARM) || StringUtils.equals(command, OneNetCollectService.GET_WARN)) {
				JsonObject con = new JsonObject();
				con.put("addr", Arrays.asList("1"));
				json.put("content", con.toString());

			} else if (StringUtils.equals(command, OneNetCollectService.SET_LEAK)) {
				JsonArray arr = new JsonArray();
				arr.add("1");
				json.put("content", arr.toString());
			} else if (StringUtils.equals(command, OneNetCollectService.SET_TITLE)) {
				JsonArray arr = new JsonArray();
				arr.add("1");
				arr.add("线路一");
				json.put("content", arr.toString());
			} else if (StringUtils.equals(command, OneNetCollectService.SET_TIME)) {
				JsonArray arr = new JsonArray();
				arr.add("Asia/Shanghai");
				arr.add(TimeUtil.getCurrentDatetime(TimeUtil.TimeFormat.LONG_DATE_PATTERN_MM));
				json.put("content", arr.toString());
			} else if (StringUtils.equals(command, OneNetCollectService.SET_REALTIME)) {
				JsonArray arr = new JsonArray();
				arr.add("30");
				json.put("content", arr.toString());
			} else if (StringUtils.equals(command, OneNetCollectService.GET_REALTIME)) {
				json.put("content", "{}");
			} else if (StringUtils.equals(command, OneNetCollectService.CLOSE_WARN_ALARM)) {
				json.put("content", "{}");
			} else if (StringUtils.equals(command, OneNetCollectService.SET_EN_REALTIME)) {
				JsonArray arr = new JsonArray();
				arr.add("close");
				json.put("content", arr.toString());
			}

		json.put("imei", imei);
		json.put("deviceType", "ZHUOWEN");
		json.put("command", command);

		return oneNetC.cmd(json.toString());
	}

    @ApiOperation(value="增加设备测试", notes="增加设备测试")
    @GetMapping("/deviceAdd")
    public String deviceAdd(String dtuType, String deviceId, Integer port, String companyId, String hardwareType, String source) {
		if (StringUtils.equals(dtuType, "2")) {
			JsonObject json = new JsonObject();
			json.put("dtuType", 2);
			json.put("port", "" + port);
			json.put("platform", 2);
			json.put("hardwareType", 42);
			collectorService.deviceAdd(json.toString());
			redis.set("port_" + port+"_1", "aaa_2_40", h -> {

			});
		}else if (StringUtils.equals(dtuType, "11")) {
			JsonObject json = new JsonObject();
			json.put("deviceType", "00ec6ae2-4c96-11ea-8f57-525400c9d3a1");
			json.put("dtuType", dtuType);
			json.put("port", "" + 62002);
			json.put("heartPackage", "51");
			json.put("companyId", "companyId");
			json.put("hardwareType", "hardwareType");
			json.put("cmdList", "{}");
			redis.hmset("mod_" + 62002, json, h -> {

			});
		}if (StringUtils.equals(dtuType, "10")) {
			if (port==null){
				port=62010;
			}
			JsonObject json = new JsonObject();
			json.put("deviceType", "00ec6ae2-4c96-11ea-8f57-525400c9d3a1");
			json.put("dtuType", dtuType);
			json.put("port", "" + port);
			json.put("heartPackage", "51");
			json.put("companyId", "companyId");
			json.put("hardwareType", "hardwareType");
			json.put("cmdList", "{}");
			redis.hmset("mod_" + port, json, h -> {

			});
		}  else if (StringUtils.equals(dtuType, "7")) {
			JsonObject json = new JsonObject();
			json.put("deviceType", "00ec6ae2-4c96-11ea-8f57-525400c9d3a1");
			json.put("dtuType", "7");
			json.put("port", "62001");
			json.put("source", "platform");
			json.put("dtuType", "7");
			json.put("heartPackage", "51");
			json.put("electricParmas", "{}");
			json.put("serverAddress", "124-202-228-190-62002");
			redis.hmset("mod_" + 62001, json, h -> {

			});
		} else if (StringUtils.equals(dtuType, "13")) {
			port = 62008;
			JsonObject config = new JsonObject();
			config.put("port", port + "");
			config.put("dtuType", "13");
			config.put("companyId", companyId);
			config.put("heartPackage", "31");
			config.put("hardwareType", hardwareType);
			config.put("currentRatio", 1);
			config.put("source", source==null?"platform":"bank");
			if (deviceId == null) {
				config.put("deviceList", new JsonArray(Arrays.asList("98CC4D00115F", "98CC4D3001CB", "98CC4D001176")).toString());
			} else {
				config.put("deviceList", new JsonArray(Arrays.asList(deviceId)).toString());
			}
			serialPortService.deviceAdd(config.toString());
		}else {
			JsonObject config = new JsonObject();
			config.put("port", port + "");
			config.put("dtuType", dtuType);
			config.put("companyId", "companyId");
			config.put("heartPackage", "31");
			config.put("hardwareType", "hardwareType");
			serialPortService.deviceAdd(config.toString());
		}
		return "小样儿";
	}
	@ApiOperation(value="删除设备测试", notes="删除设备测试")
	@GetMapping("/devicedel")
	public String devicedel(String str) throws JobExecutionException {
		int port = 62008;
		JsonObject config=new JsonObject();
		config.put("port", port+"");
		config.put("dtuType", "13");
		config.put("companyId", "companyId");
		config.put("heartPackage", "31");
		config.put("hardwareType", "hardwareType");
		if (str==null){
			config.put("deviceList", new JsonArray(Arrays.asList("98CC4D00115F","98CC4D3001CB","98CC4D001176")).toString());
		}else {
			config.put("deviceList", new JsonArray(Arrays.asList(str)).toString());
		}
//        collectorService.cmd(addConfig.toString());
		serialPortService.deviceDelete(config.toString());
		return "小样儿";
	}
	@ApiOperation(value="onenet获取所有设备", notes="onenet获取所有设备")
	@GetMapping("/error2")
	public String error2(String a)  throws  Exception{
		JsonObject params = new JsonObject();
		params.put("imei",a);
		params.put("deviceType","ZHUOWEN");
		params.put("imsi",a);
		params.put("name",a);
		oneNetCollectService.deviceAdd(params.toString());
		OneNetResult device = oneNetCollectService.getAllDevice(1);
		return device.toString();
	}


	@GetMapping("/title")
	public String basdsds() throws JobExecutionException {

		Map<String, String> params = new HashMap<String, String>();
		params.put("title", "aa");
		HttpClientResult result = null;
		try {
			result = HttpClientUtils.doGet(Constant.ALERT, params);
		} catch (Exception e) {
			logger.info("invoke flatform alerts fail");
			e.printStackTrace();
		}
		System.out.println(result);
		return result.toString();
	}
    @ApiOperation(value="单独命令测试", notes="单独命令测试",produces = "application/json")
	@GetMapping("/cmd")
	public String cmd(Integer port, String cmd,String cmdId) throws JobExecutionException {
		EventBus eventBus = vertx.eventBus();
		if (port==null){
		    port=62009;
        }

        if (cmd==null){
            cmd="100";
        }
		if (cmdId==null){
			cmdId="A2";
		}
		eventBus.publish(Constant.ONLY_CMD + port, new JsonObject().put("cmd", cmd.trim()).put("cmdId",cmdId));
		return "小样儿";
	}

	@GetMapping("/closeServer")
	public String closeServer(int port, String cmd) throws JobExecutionException {
		EventBus eventBus = vertx.eventBus();
		eventBus.send("closeserver" , new JsonObject());
		return "小样儿";
	}

	@GetMapping("/cmd2")
	public String cmd2(int port,String deviceCode,String data,String oper) throws JobExecutionException {
		if(data==null){
			data="10";
		}
		String l = String.format("%02x", deviceCode.length() / 2);
		String cmd=null;
		if (StringUtils.equals("B0", oper)){
			cmd = OnlyServer.splicCmd("8881B0030A" + "0000000000000000", l+deviceCode + data);
		}else if(StringUtils.equals("A0", oper)){
			cmd= OnlyServer.splicCmd("8881", "A0", "030A" + "0000000000000000", l+deviceCode + "00");
		}else if(StringUtils.equals("A1", oper)){
			cmd= OnlyServer.splicCmd("8881", oper, "030A" + "0000000000000000", l+deviceCode + "01"+"2102"+"02"+"0032");
		}
		EventBus eventBus = vertx.eventBus();
		eventBus.send("connector.cmd." + port, new JsonObject().put("cmd", cmd));

		return "小样儿";

	}

	@GetMapping("/rpc")
	public String rpc(Integer deviceNum, String sendId, String value, int port, String flag, Integer hardwareType,
			Integer dtutype) throws JobExecutionException {
		if (StringUtils.isEmpty(flag)) {
			flag = "write";
		}
		if (hardwareType == null) {
			hardwareType = 1;
		}
		if (dtutype == null) {
			dtutype = 2;
		}
		if (deviceNum == null) {
			deviceNum = 1;
		}
		JSONObject data = new JSONObject();
		data.put("dtutype", dtutype);
		data.put("hardwareType", hardwareType);
		data.put("port", port);
		data.put("source", "app");
		data.put("sendId", sendId);// 0024 消音 0025复位
		data.put("value", value);
		data.put("flag", flag);
		data.put("deviceNum", deviceNum); // 地址码

		logger.info("-->发送命令： " + data.toString());

		collectorService.cmd(data.toJSONString());
		return "小样儿";
	}

	@GetMapping("/cmdZhong")
	public void cmdZhong(String s, String t, Integer p) throws JobExecutionException {
		EventBus eventBus = vertx.eventBus();
		JsonObject cmdConfig = new JsonObject();
		if (s == null) {
			if ("5".equals(t)) {
				cmdConfig = new JsonObject();
				cmdConfig.put("operationNum", 5);
				cmdConfig.put("gatewayType", "ygateway");
				cmdConfig.put("dtutype", 2);
				cmdConfig.put("port", p);
				cmdConfig.put("content", "0103");
			} else if ("6".equals(t)) {
				cmdConfig = new JsonObject();
				cmdConfig.put("operationNum", 6);
				cmdConfig.put("gatewayType", "ygateway");
				cmdConfig.put("dtutype", 2);
				cmdConfig.put("port", p);
				JsonObject cc = new JsonObject();
				JsonArray jsonArray = new JsonArray();
				jsonArray.add(new JsonObject().put("pro", "106").put("sid", "0001"));
				jsonArray.add(new JsonObject().put("pro", "117").put("sid", "F003"));
				jsonArray.add(new JsonObject().put("pro", "116").put("sid", "0002"));
				cc.put("slaves", jsonArray);
				// {"slaves":[{"pro":"106","sid":"0002"},{"pro":"117","sid":"F001"}]}
				cmdConfig.put("content", cc.toString());

			} else if ("7".equals(t)) {
				cmdConfig = new JsonObject();
				cmdConfig.put("operationNum", 6);
				cmdConfig.put("gatewayType", "ygateway");
				cmdConfig.put("dtutype", 2);
				cmdConfig.put("port", p);
				JsonObject cc = new JsonObject();
				JsonArray jsonArray = new JsonArray();
				jsonArray.add(new JsonObject().put("pro", "106").put("sid", "0001"));
				jsonArray.add(new JsonObject().put("pro", "117").put("sid", "F003"));
				jsonArray.add(new JsonObject().put("pro", "116").put("sid", "0002"));
				jsonArray.add(new JsonObject().put("pro", "106").put("sid", "0004"));
				cc.put("slaves", jsonArray);
				// {"slaves":[{"pro":"106","sid":"0002"},{"pro":"117","sid":"F001"}]}
				cmdConfig.put("content", cc.toString());

			}else if ("15".equals(t)) {
				cmdConfig.put("operationNum", 15);
				cmdConfig.put("content", "at+ver\r");
				cmdConfig.put("gatewayType", "ygateway");
				cmdConfig.put("dtutype", 2);
				cmdConfig.put("port", p);
			} else if ("16".equals(t)) {
				cmdConfig.put("operationNum", 15);
				cmdConfig.put("content", "at+imei\r");
				cmdConfig.put("gatewayType", "ygateway");
				cmdConfig.put("dtutype", 2);
				cmdConfig.put("port", p);
			}
		} else {
			cmdConfig = new JsonObject(s);
		}
		logger.info("rpc receive cmd msg: " + s);
		Integer port = cmdConfig.getInteger("port");
		Integer dtutype = cmdConfig.getInteger("dtutype");
		Integer hardwareType = cmdConfig.getInteger("hardwareType");
		Integer deviceNum = cmdConfig.getInteger("deviceNum");
		String source = cmdConfig.getString("source");
		String gateway = cmdConfig.getString("gatewayType");
		String content = cmdConfig.getString("content");
		Integer operationNum = cmdConfig.getInteger("operationNum");

		String sendCmd = "";
		String devicestr = "";

		if (gateway != null && gateway.equals("ygateway") && dtutype == 2) {

			String len = "";
			String ycmd = "";
			String initcmd = "";

			String binary = "00000001";
			String contro = String.format("%02x", Integer.parseInt(binary, 2));
			devicestr = String.format("%04x", 1);
			String operationNumHex = String.format("%02x", operationNum);

			if (operationNum == 6) {
				initcmd = Utils.bytes2String(content.getBytes());
				len = String.format("%04x", content.getBytes().length);

			} else if (operationNum == 5) {
				len = "0002";
				initcmd = content;
			} else if (operationNum == 15) {
				len = String.format("%04x", content.getBytes().length);
				initcmd = Utils.bytes2String(content.getBytes());
			}
			ycmd = addStr("2B", contro, devicestr, operationNumHex, len, initcmd);
			sendCmd = addStr(ycmd, Utils.checkNumFisrt(ycmd), "16").toUpperCase();

			logger.info("send cmd" + port + "--" + sendCmd);
			eventBus.send("connector.cmd." + port, new JsonObject().put("port", port).put("cmd", sendCmd));
			return;
		}

		if (StringUtils.equals(source, "app")) {
			String sendId = cmdConfig.getString("sendId");
			String value = cmdConfig.getString("value");
			String flag = cmdConfig.getString("flag");
			String deviceType = "";
			if (StringUtils.equals(sendId, "signal")) {
				sendCmd = "at-usr.cnAT+CSQ\r";
			} else {

				devicestr = String.format("%02x", deviceNum).toUpperCase();
				String[] splitAddress = sendId.split("~");
				String startAddress = splitAddress[0].substring(0, 4);
				String endAddress = splitAddress[splitAddress.length - 1].substring(0, 4);
				List<Command> comm = new ArrayList<>();
				if (hardwareType == 0 || hardwareType == 1 || hardwareType == 31 || hardwareType == 41
						|| hardwareType == 40) {
					deviceType = "106";
					comm = commandMapper.findAllByAddressAll(startAddress, endAddress, deviceType);
				} else if (hardwareType == 2 || hardwareType == 4 || hardwareType == 42) {
					deviceType = "117";
					comm = commandMapper.findAllBySendIdAll(splitAddress[0], splitAddress[splitAddress.length - 1],
							deviceType);
				}
				if (!comm.isEmpty()) {
					startAddress = comm.get(0).getAddress();
				} else {
					logger.info("无此命令");
					return;
				}
				int b = 0;
				String hexValue = "";
				if (StringUtils.equals(flag, "write")) {
					String[] splitValue = value.split("~");
					for (int i = 0; i < comm.size(); i++) {
						if (sendId.length() > 4) {
							b = b + 1;
							int binaryValue = 0;
							String binaryType = "";
							if (StringUtils.equals(splitAddress[i].substring(4), "0")) {
								binaryType = Integer.toBinaryString(0);
								binaryValue = Integer.parseInt(splitValue[i]);
							} else if (StringUtils.equals(splitAddress[i].substring(4), "1")) {
								binaryType = Integer.toBinaryString(1);
								binaryValue = Integer.parseInt(splitValue[i]);
							} else if (StringUtils.equals(splitAddress[i].substring(4), "2")) {
								binaryType = Integer.toBinaryString(2);
								binaryValue = Integer.parseInt(splitValue[i]) + 3000;
							} else if (StringUtils.equals(splitAddress[i].substring(4), "3")) {
								binaryType = Integer.toBinaryString(3);
								binaryValue = Integer.parseInt(splitValue[i]) * 10;
							} else if (StringUtils.equals(splitAddress[i].substring(4), "4")) {
								binaryType = Integer.toBinaryString(4);
								binaryValue = Integer.parseInt(splitValue[i]) * 10;
							}

							String v = addStr(String.format("%03d", Long.parseLong(binaryType)),
									String.format("%013d", Long.parseLong(Long.toBinaryString(binaryValue))));
							hexValue = hexValue + String.format("%04x", Integer.valueOf(v, 2));
						} else {
							b = b + comm.get(i).getByteNum();
							String type = comm.get(i).getType();
							if (StringUtils.equals(type, "5")) {
								String v = String.format("%02x", Integer.parseInt(splitValue[i]));
								hexValue = hexValue + v + v;
							}
							if (StringUtils.equals(type, "6")) {
								hexValue = hexValue + String.format("%04x", Integer.parseInt(splitValue[i]));
							} else if (StringUtils.equals(type, "10")) {
								hexValue = hexValue + String.format("%04x", Integer.parseInt(splitValue[i]) * 10);
							} else if (StringUtils.equals(type, "11")) {
								hexValue = hexValue + splitValue[i];
							} else if (StringUtils.equals(type, "12")) {
								for (String st : splitValue[i].split("-")) {
									hexValue = hexValue + String.format("%04x", Integer.parseInt(st));
								}
							} else if (StringUtils.equals(type, "13")) {
								Integer len = comm.get(i).getByteNum() * 4;
								hexValue = hexValue + String.format("%0" + len + "x", Integer.parseInt(splitValue[i]));
							} else if (StringUtils.equals(type, "15")) {
								Integer len = comm.get(i).getByteNum() * 4;
								hexValue = hexValue
										+ String.format("%0" + len + "x", Long.parseLong(splitValue[i]) * 10000);
							}
						}
					}
				}
				String byteLength = String.format("%02x", b * 2);
				String byteNum = String.format("%04x", b);

				if (deviceType.equals("106")) {
					if (StringUtils.equals(flag, "write")) {
						sendCmd = Utils.checkNumSecondAll(
								addStr(devicestr + "10", startAddress, byteNum, byteLength, hexValue));
						readMap.put(port + "w", sendCmd);
					} else {
						sendCmd = Utils.checkNumSecondAll(addStr(devicestr + "03", startAddress,
								String.format("%04x", comm.stream().mapToInt(Command::getByteNum).sum())));
						readMap.put(port + "", sendCmd);
						readMap.put(devicestr + port, comm);
					}

				} else if (deviceType.equals("117")) {
					if (StringUtils.equals(flag, "write")) {
						sendCmd = "68" + Utils.checkNumFisrtAll(
								addStr("F0", devicestr + "10", startAddress, byteNum, byteLength, hexValue));
						readMap.put(port + "w", sendCmd);
					} else {
						sendCmd = "68" + Utils.checkNumFisrtAll(addStr("F0", devicestr + "03", startAddress,
								String.format("%04x", comm.stream().mapToInt(Command::getByteNum).sum()) + ""));
						readMap.put(port + "", sendCmd);
						readMap.put(devicestr + port, comm);
					}

				} else if (dtutype == 0 && hardwareType == 10) {

				}
			}

			if (!StringUtils.isEmpty(sendCmd)) {
				if (dtutype == 2 && (deviceType.equals("117") || deviceType.equals("106"))) {
					String binary = "00000001";
					String contro = String.format("%02x", Integer.parseInt(binary, 2));
					devicestr = String.format("%04x", deviceNum);
					String le = String.format("%04x", sendCmd.length() / 2);
					String firstLe = String.format("%04x", sendCmd.length() / 2 + 9);
					String ycmd = addStr("2B", contro, devicestr, "03", firstLe, "02", "01F4", "00002580", le, sendCmd);
					sendCmd = addStr(ycmd, Utils.checkNumFisrt(ycmd), "16").toUpperCase();
				}
				logger.info(sendCmd);
				eventBus.send("connector.cmd." + port, new JsonObject().put("port", port).put("cmd", sendCmd));
			}

		} else {
			String operation = cmdConfig.getString("operation");
			String cmd = cmdConfig.getString("cmd");
			if (dtutype == 0) {
				eventBus.send("connector.cmd." + port, new JsonObject().put("port", port).put("cmd", cmd));
			} else if (dtutype == 1) {
				StringBuilder sb = new StringBuilder();
				if (deviceNum < 10) {
					devicestr = "0" + deviceNum;
				} else {
					devicestr = deviceNum + "";
				}
				if (StringUtils.equals(operation, "clean")) {
					sb.append(devicestr).append(Constant.CLEAN_106);
				} else {
					sb.append(devicestr).append(Constant.RESET_106);
				}
				String checkNumSecond = Utils.checkNumSecond(sb.toString());
				sb.append(checkNumSecond).insert(0, Constant.ZHOGNHUISTART);
				String checkNumFisrt = Utils.checkNumFisrt(sb.toString());
				sb.append(checkNumFisrt).append("16");
				eventBus.send("connector.cmd." + port, new JsonObject().put("port", port).put("cmd", sb.toString()));

			} else if (dtutype == 2) {
				StringBuilder sb = new StringBuilder();
				if (deviceNum < 10) {
					devicestr = "0" + deviceNum;
				} else {
					devicestr = deviceNum + "";
				}
				if (StringUtils.equals(operation, "clean")) {
					sb.append(devicestr).append(Constant.CLEAN_106);
				} else {
					sb.append(devicestr).append(Constant.RESET_106);
				}
				String checkNumSecond = Utils.checkNumSecond(sb.toString());
				sb.append(checkNumSecond).insert(0, Constant.ZHOGNHUISTART);
				String checkNumFisrt = Utils.checkNumFisrt(sb.toString());
				sb.append(checkNumFisrt).append("16");
				eventBus.send("connector.cmd." + port, new JsonObject().put("port", port).put("cmd", sb.toString()));
			}
		}

	}

	@GetMapping("/readStart")
	public String readStart(int port, Integer hardwareType, String deviceId, String cmd, Double rate)
			throws JobExecutionException {
		if (deviceId == null) {
			deviceId = "";
		}
		if (cmd == null) {
			cmd = "68F001036000001468";
		}
		if (hardwareType == null) {
			hardwareType = 2;
		}
		if (rate == null) {
			rate = 15.0;
		}

		vertx.eventBus().publish("connector.read.start." + port,
				new JsonObject().put("port", port).put("hardware_type", hardwareType).put("deviceId", deviceId)
						.put("cmd", cmd).put("rate", rate).put("ct", 1).put("pt", 1).put("lct", 1)
						.put("warn", new JsonObject()).put("platform", 1));
		return "yes";
	}

	@GetMapping("/checkNumFisrt")
	public String b(String cmd) throws JobExecutionException {

		return Utils.checkNumFisrt(cmd);
	}

	@GetMapping("/checkNumSecond")
	public String c(String cmd) throws JobExecutionException {
		return Utils.checkNumSecond(cmd);
	}

	@GetMapping("/xiyucmd")
	public void cmd(String msg) throws InterruptedException {
		logger.info("XiYuServiceimp cmd rpc :" + msg);
		JsonObject json = new JsonObject(msg);
		int fDetectorAddress = json.getInteger("fDetectorAddress");
		String cmd = json.getString("cmd");
		String deviceId = json.getString("deviceId");
		String serviceId = "";
		String method = "";
		int fDetectorType;
		int fCommandType;
		Integer fValue = null;
		if (StringUtils.equals(cmd, "rest")) {
			serviceId = "detectorMute";
			method = "SingleMute";
			fDetectorType = 4;
			fCommandType = 5;
			fValue = 0;
			try {
				telecomService.cmd(deviceId, serviceId, method, fDetectorAddress, fDetectorType, fCommandType, fValue);
			} catch (Exception e) {
				e.printStackTrace();
			}
			sleep(3000);
			fValue = null;
			serviceId = "detectorReset";
			method = "SingleReset";
			fDetectorType = 4;
			fCommandType = 3;

		} else if (StringUtils.equals(cmd, "mute")) {
			serviceId = "detectorMute";
			method = "SingleMute";
			fDetectorType = 4;
			fCommandType = 5;
			fValue = json.getInteger("fValue");
		} else {
			serviceId = "detectorStatus";
			method = "QueryStatus";
			fDetectorType = 4;
			fCommandType = 1;

		}
		logger.debug("XiYuServiceimp cmd rpc :" + cmd);
		try {
			telecomService.cmd(deviceId, serviceId, method, fDetectorAddress, fDetectorType, fCommandType, fValue);
		} catch (Exception e) {
			e.printStackTrace();
		}

		if (StringUtils.equals(cmd, "rest")) {

		}

	}

	@GetMapping("/mongoTemplate")
	public Object contextLoads(Jackson2ObjectMapperBuilder dd) {

		try {
//			moveData(Company.class);
//			moveData(Device.class );
//			moveData(Group.class);
//			moveData(RealTimeData.class);
			logger.info("-----");
//			List<Company> findAll = secondMongoTemplate.findAll(Company.class);
//			List<Device> findAll2 = secondMongoTemplate.findAll(Device.class);
//			List<Group> findAll3 = secondMongoTemplate.findAll(Group.class);
			long coun1t = mongoTemplate.query(RealTimeData.class).count();
			List<RealTimeData> findAll4 = null;
			// findAll4 = secondMongoTemplate.findAll(RealTimeData.class);
			logger.info("-----" + coun1t + "--" + coun1t);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return 1;
	}

	public static String addStr(String... args) {
		StringBuilder sb = new StringBuilder();
		for (String temp : args) {
			sb.append(temp);
		}
		return sb.toString();
	}

//	public static final String DATE_STRING = "__vertx.net.b17da961-be3b-407b-a801-74b7d52ca562==>false==>队列个数:0==>port:42862==>cmd:01038000000C6C0F";
//	public static final String P_COMM = "^.*port:(.*)$";
	public static final String DATE_STRING = "deviceId:901801030058 ==> currentMessage：01 03 92 00 18 01 03 00 58 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 27 01 25 01 25 01 24 59 B3 59 C7 59 A5 00 9A 00 0F 00 00 00 06 00 1B 00 03 00 00 00 1E 00 16 FF FF 00 00 00 15 03 03 03 A4 03 E8 03 35 13 8A 00 0E 6A C5 00 1A 39 02 00 14 79 C2 00 02 D4 60 00 31 86 70 00 09 00 0D 00 00 00 12 00 19 00 0D 00 43 00 41 00 41 00 1D 00 18 00 16 00 0E 00 10 00 0F 00 0F 00 16 00 15 27 10 27 10 27 10 00 5E 00 5F 00 5E 02 D5 00 00 00 00 3D E3";
	public static final String P_COMM = "^deviceId:(9\\d*).*$";

	public static void main(String[] args) {
		
		String aa=new String("7B22736C61766573223A5B7B2270726F223A22313036222C22736964223A2230303031227D2C7B2270726F223A22313136222C22736964223A2230303032227D2C7B2270726F223A22313137222C22736964223A2246303033227D5D7".getBytes());
		

		String content = "at+ver\r";

		String binary = "00000001";
		String contro = String.format("%02x", Integer.parseInt(binary, 2));
		String devicestr = String.format("%04x", 1);
		String operationNumHex = String.format("%02x", 15);
		String le = String.format("%04x", content.getBytes().length + 2);
		String len = String.format("%04x", content.getBytes().length);
		String ycmd1 = addStr("2B", contro, devicestr, operationNumHex, len, Utils.bytes2String(content.getBytes()));
		String sendCmd1 = addStr(ycmd1, Utils.checkNumFisrt(ycmd1), "16").toUpperCase();
		System.out.println(sendCmd1);
//		Pattern pattern = Pattern.compile(P_COMM);
//		Matcher matcher = pattern.matcher(DATE_STRING);
//		boolean find = matcher.find();//必须要有这句
//		if(find) {
//			System.out.printf("\nmatcher.group(0) value:%s", matcher.group(0));
//		}

	}

}